package com.show.controller;

import com.shop.entity.classify.Classify;
import com.shop.service.classify.ClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 * 分类模块
 */
@RestController
@RequestMapping("class")
public class ClassifyController {
    @Autowired
    ClassifyService classifyService;

    /***
     * 实体筛选多条数据
     * @param classify
     * @return
     */
    @PostMapping("queryAlllist")
    public Dto querylist(Classify classify){
        return DtoUtil.returnDataSuccess(classifyService.queryAll(classify));
    }
    /***
     * 分页查询多条数据
     */
    @GetMapping("querylist")
    public Dto querylist(int page,int limit){
        return DtoUtil.returnPage(
                classifyService.queryAllByLimit((page-1)*limit,limit),classifyService.getCount()
        );
    }

    /***
     * 根据主键id删除数据
     * @param id
     * @return
     */
    @PostMapping("deleteById")
    public Dto deleteById(int id){
        if(classifyService.deleteById(id)!=0){
            return DtoUtil.returnSuccess("删除成功");
        }else {
            return DtoUtil.returnFail("删除失败",500);
        }
    }
}
